<?php
	require_once("global.php");
	require_once("modules/security_mod.php");
	require_once("alerter/modules/account_mod.php");
	require_once("alerter/modules/alert_mod.php");
	require_once("modules/level_mod.php");
	require_once("page_navigator.php");

	SecurityMod::login();

	$level = $_SESSION["account"]->getLevel();
	if ($level != "Admin" && $level != "AlertUser")
		SecurityMod::logout();

	$pageNumber = intval(v($_REQUEST, "page"));
	if ($pageNumber < 1)
		$pageNumber = 1;

	function drawNavigator() {
		global $pageCount, $pageNumber;
		$params = "";
		PageNavigator::draw($pageCount, $pageNumber, 33, $params, "accounts.php");
	}
	
	$filterCluster = v($_REQUEST, "cluster");

	$alerts= AlertMod::getAlertsForList($filterCluster);

	$levels = LevelMod::getLevels();
?>
<html>
<head>
<title><?php echo(SettingsMod::PAGE_TITLE." :: Alerts"); ?></title>
<link rel="stylesheet" href="main.css">
<script src="main.js" type="text/javascript"></script>
<script src="info.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
	function combatDetails(combatId) {
		var leftPos = 0;
		var topPos = 0;
		if (screen) {
			leftPos = (screen.width / 2) - 375;
			topPos = (screen.height / 2) - 275;
		}
		window.open("combat_details.php?id=" + combatId, "_blank", "width=750,height=550,scrollbars=1,resizable=1,left=" + leftPos + ",top=" + topPos);
	}
	
	function hackDetails(hackId) {
		var leftPos = 0;
		var topPos = 0;
		if (screen) {
			leftPos = (screen.width / 2) - 375;
			topPos = (screen.height / 2) - 275;
		}
		window.open("hack_details.php?id=" + hackId, "_blank", "width=750,height=550,scrollbars=1,resizable=1,left=" + leftPos + ",top=" + topPos);
	}
	
	function manualDetails(manId) {
		var leftPos = 0;
		var topPos = 0;
		if (screen) {
			leftPos = (screen.width / 2) - 375;
			topPos = (screen.height / 2) - 275;
		}
		window.open("manual_details.php?id=" + manId, "_blank", "width=750,height=550,scrollbars=1,resizable=1,left=" + leftPos + ",top=" + topPos);
	}
</script>
</head>
<body>
	<h2 align="center">Current Alerts</h2>
	<table align="center" width="700">
	<tr>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td align="center">
			<table background="<?php echo(SettingsMod::STATIC_IMAGES)?>/bgd.gif" class="messagestyle" align="center" width="100%">
			<tr>
				<td colspan="8">&nbsp;</td>
			</tr>
			<tr>
				<th>&nbsp;</th>
				<th><u>Date</u></th>
				<th><u>Type</u></th>
				<th><u>Cluster</u></th>
				<th><u>Location</u></th>
				<th><u>Attacker</u></th>
				<th><u>Defender</u></th>
				<th><u>Cleared</u></th>
			</tr>
			<?php
				$i = 0;
				foreach ($alerts as $alrt):
				$i++;
				$detailLink = "";
				if ($alrt->getType() == "CMBT") {
					$detailLink = "combatDetails(".$alrt->getLogID().")";				
				} elseif ($alrt->getType() == "HACK"){
					$detailLink = "hackDetails(".$alrt->getLogID().")";				
				} elseif ($alrt->getType() == "MANL"){
					$detailLink = "manualDetails(".$alrt->getLogID().")";				
				}
			?>
			<tr bgcolor='#0b0b2f' onMouseOver='chOn(this)' onMouseOut='chOut(this)' onClick='chClick(this)'>
				<td align='right' style='cursor:crosshair' onClick='<?php echo($detailLink)?>'>
					<?php echo($i)?>.
				</td>
				<td align='center' style='cursor:crosshair' onClick='<?php echo($detailLink)?>'>
					<script language="javascript">document.write(formatDate(<?php echo(strtotime($alrt->getDate()) * 1000)?>))</script>
				</td>
				<td align='center' style='cursor:crosshair' onClick='<?php echo($detailLink)?>'><?php echo($alrt->getType())?></td>
				<td align='center' style='cursor:crosshair' onClick='<?php echo($detailLink)?>'><?php echo($alrt->getCluster())?></td>
				<td align='center' style='cursor:crosshair' onClick='<?php echo($detailLink)?>'><?php echo($alrt->getSector() . " " . $alrt->getCoords())?></td>
				<td align='center' style='cursor:crosshair' onClick='<?php echo($detailLink)?>'><?php echo($alrt->getOffender())?></td>
				<td align='center' style='cursor:crosshair' onClick='<?php echo($detailLink)?>'><?php echo($alrt->getName())?></td>
				<td align='center' style='cursor:crosshair' onClick='<?php echo($detailLink)?>'><?php echo($alrt->getCleared())?></td>
			</tr>
			<?php endforeach?>
			<tr>
				<td colspan="8">&nbsp;</td>
			</tr>
			</table>
		</td>
	</tr>
	</table>
	<div id="tipBox"></div>
</body>
</html>